<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="商户订单号" prop="outtradeno">
        <el-input
          v-model="queryParams.outtradeno"
          placeholder="请输入商户订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付宝订单号" prop="tradeno">
        <el-input
          v-model="queryParams.tradeno"
          placeholder="请输入支付宝订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充值人员id" prop="userid">
        <el-input
          v-model="queryParams.userid"
          placeholder="请输入充值人员id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充值人姓名，冗余" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入充值人姓名，冗余"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充值金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入充值金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付宝接口返回的msg" prop="msg">
        <el-input
          v-model="queryParams.msg"
          placeholder="请输入支付宝接口返回的msg"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付宝接口返回的sub_code" prop="subCode">
        <el-input
          v-model="queryParams.subCode"
          placeholder="请输入支付宝接口返回的sub_code"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付宝接口返回的sub_msg" prop="subMsg">
        <el-input
          v-model="queryParams.subMsg"
          placeholder="请输入支付宝接口返回的sub_msg"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务处理结果" prop="result">
        <el-input
          v-model="queryParams.result"
          placeholder="请输入业务处理结果"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker
          clearable
          size="small"
          style="width: 200px"
          v-model="queryParams.createtime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="终端IP" prop="terminalip">
        <el-input
          v-model="queryParams.terminalip"
          placeholder="请输入终端IP"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['monitor:rechargeLog:export']"
          >导出</el-button
        >
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="终端IP" align="center" prop="id" />
      <el-table-column label="商户订单号" align="center" prop="outtradeno" />
      <el-table-column label="支付宝订单号" align="center" prop="tradeno" />
      <el-table-column label="姓名" align="center" prop="username" />
      <el-table-column label="金额" align="center" prop="amount" />
      <el-table-column label="trade_status" align="center" prop="tradestatus" />
      <el-table-column label="code" align="center" prop="code" />
      <el-table-column label="描述" align="center" prop="msg" />
      <el-table-column label="sub_code" align="center" prop="subCode" />
      <el-table-column label="sub_msg" align="center" prop="subMsg" />
      <el-table-column label="结果" align="center" prop="result" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creaTetime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="终端IP" align="center" prop="terminalip" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listLog, getLog, delLog } from '@/api/monitor/rechargeLog'

export default {
  name: 'Log',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 充值接口日志（个人->商家）表格数据
      logList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        outtradeno: undefined,
        tradeno: undefined,
        userid: undefined,
        username: undefined,
        amount: undefined,
        type: undefined,
        tradestatus: undefined,
        code: undefined,
        msg: undefined,
        subCode: undefined,
        subMsg: undefined,
        result: undefined,
        createTime: undefined,
        terminalip: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询充值接口日志（个人->商家）列表 */
    getList() {
      this.loading = true
      listLog(this.queryParams).then((response) => {
        this.logList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        outtradeno: undefined,
        tradeno: undefined,
        userid: undefined,
        username: undefined,
        amount: undefined,
        type: undefined,
        tradestatus: '0',
        code: undefined,
        msg: undefined,
        subCode: undefined,
        subMsg: undefined,
        result: undefined,
        createtime: undefined,
        terminalip: undefined,
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          // if (this.form.id != undefined) {
          //   updateLog(this.form).then(response => {
          //     if (response.code === 200) {
          //       this.msgSuccess("修改成功");
          //       this.open = false;
          //       this.getList();
          //     } else {
          //       this.msgError(response.msg);
          //     }
          //   });
          // } else {
          addLog(this.form).then((response) => {
            if (response.code === 200) {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            } else {
              this.msgError(response.msg)
            }
          })
          // }
        }
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有充值接口日志（个人->商家）数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          return exportLog(queryParams)
        })
        .then((response) => {
          this.download(response.msg)
        })
        .catch(function () {})
    },
  },
}
</script>
